<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>




     <div class="am-cf am-padding">
        <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">微店管理</strong> / <small>分类设置</small></div>
      </div>

      <div class="am-g">
        <div class="am-u-sm-12">
	        <form class="am-form-inline" role="form">
			  <div class="am-form-group">
			    <input type="text" class="am-form-field" placeholder="分类名" id="catNewName">
			  </div>
			
			  <div class="am-form-group">
			    <input type="number" class="am-form-field" placeholder="显示排序" id="catNewShowseq">
			  </div>		
			
			  <button type="button" id="submitCat" name="submitCat" class="am-btn am-btn-default">增加</button>
			</form>
	        
              
          <table class="am-table am-table-bd am-table-striped admin-content-table" id="tableCat">
            <thead>
            <tr>
              <th>ID</th><th>分类名</th><th>是否显示</th><th>显示排序</th><th>类型</th><th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${catlist}" var="c" varStatus="status">
            <tr id="tr_${c.id}"><td>${c.id}</td><td>${c.name}</td><td><input id="checkbox_${c.id}" type="checkbox" onclick="setCatShow(${c.id});" <c:choose>
   <c:when test="${c.isshow == 'Y'}"> checked </c:when> </c:choose> /> </td> 
            	<td>${c.showseq}</td><td>${c.type}</td><td>
   <c:choose><c:when test="${c.type != 'sys'}"> <input type="button" class=".am-btn-xs" value="删除" id="delCat_${c.id}" onclick="delCat(${c.id})" /></c:when> </c:choose> </td>             	
            	           
            </tr>    
            </c:forEach>
                
            </tbody>
          </table>
        </div>
      </div>

      <div class="am-g">
      	<div class="am-u-sm-12">
      	</div>
      </div>



<script>
function setCatShow(catid){
	var checked = $("#checkbox_"+catid).attr("checked");
	console.log(checked);
	var isshow = "N";
	if (checked == "checked") isshow = "Y"; 
	  $.post("/admin/doCatSetShow/",{catid:catid,isshow:isshow},function(result){
		    
		  });
}
function delCat(catid){
	 $.post("/admin/doCatDel/",{catid:catid},function(result){
		   if( result.status == 1){
			   $("#tr_"+catid).remove();
		   } 
	  });
}
$(document).ready(function(){
	$("#submitCat").click(function(){
		$.post("/admin/doCatAdd/",
				{catname:$("#catNewName").val(),catseqnum:$("#catNewShowseq").val()},
				function(result){
		    if(result.status == 1){
		    	var newrow = '<tr id="tr_'+result.data.id+'"><td>'+result.data.id+'</td><td>'+result.data.name+'</td><td><input id="checkbox_'+result.data.id+'" type="checkbox" onclick="setCatShow('+result.data.id+');" ';
		    	if( result.data.isshow === "Y"){
		    		newrow += " checked ";
		    	}
		    	newrow += '/> </td> <td>' + result.data.showseq + '</td><td>' + result.data.type + '</td>';
		    	newrow += '<td><input type="button" class=".am-btn-xs" value="删除" id="delCat_'+result.data.id+'" onclick="delCat('+result.data.id+')" /></tr>';
		    	$("#tableCat").append(newrow);
		    }
		  });
		
		return false;
	})
	
});
</script>
    